package cn.itcast.user.web;

import cn.itcast.user.pojo.User;
import cn.itcast.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 路径： /user/110
     *
     * @param id 用户id
     * @return 用户
     */
    @GetMapping("/{id}")
    public User queryById(@PathVariable("id") Long id) {
        return userService.queryById(id);
    }


    @PostMapping
    public String save(@RequestBody User user){
        System.out.println(user);
        return userService.save(user);
    }

    @DeleteMapping("/{id}")
    public void delUser(@PathVariable("id") Long id){
        userService.delUser(id);
    }

    @PutMapping
    public void putUser(@RequestBody User user){
        userService.putUser(user);
    }

    @Value("${pattern.dataformat}")
    private String format ;

    @GetMapping("/no")
    public String no (){
        return LocalDateTime.now().format(DateTimeFormatter.ofPattern(format));
    }

}
